package ts.group.webapp.market.common.job;

import java.util.HashMap;
import java.util.Map;

/**
 * 
 * 格式: [秒] [分] [小时] [日] [月] [周] [年]
 * 
 * 
 * @author zhouhua, 2013-1-18
 */
@SuppressWarnings("unchecked")
public class CronExRelated {
    public static final String _EVERY = "every";
    public static final String _ANY = "any";
    public static final String _RANGES = "ranges";
    public static final String _INCREMENTS = "increments";
    public static final String _ADDITIONAL = "additional";
    public static final String _LAST = "last";
    public static final String _WEEKDAY = "weekday";
    public static final String _THENTH = "theNth";
    public static final String _CALENDAR = "calendar";

    public static final String _TYPE = "type";

    /**
     * 0 0 6 ? * 1#1 ? monthly; 0 0 6 ? * 1 ? weekly; 0 0 6 30 7 ? 2006 useDefined
     */
    static String[] headTitle = { "TYPE", "SECONDS", "MINUTES", "HOURS", "DAYOFMONTH", "MONTH",
        "DAYOFWEEK", "YEAR" };

    /**
     * cron expression special characters Map specialCharacters
     */
    public static Map specialCharacters;

    static {
        specialCharacters = new HashMap(10);
        specialCharacters.put(_EVERY, "*");//* 代表任意合法的字段 
        specialCharacters.put(_ANY, "?");//? 表示没值被指定 ,只能出现在月和星期的字段
        specialCharacters.put(_RANGES, "-");//- 表示值的范围 
        specialCharacters.put(_INCREMENTS, "/");// / 表示时间的增量 
        specialCharacters.put(_ADDITIONAL, ",");//表示指定多个值，例如在周字段上设置 "MON,WED,FRI" 表示周一，周三和周五触发
        specialCharacters.put(_LAST, "L");//L 如果用在"一月哪天"段上，表示一个月的最后一天；如果用在"星期"段上。表示一个星期的最后一天（星期六）
        specialCharacters.put(_WEEKDAY, "W");//W 表示最靠近给定时间的一天，（必须是星期一到星期五）
        specialCharacters.put(_THENTH, "#");//只能出现在"星期"段位置 ,表示第几个星期
        specialCharacters.put(_CALENDAR, "C");

        specialCharacters.put(_TYPE, headTitle);
    }

    public static void set(String ex, int index) {
        ((String[]) specialCharacters.get(_TYPE))[index] = ex;
    }
}
